<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建人姓名">
          <a-input placeholder="请输入创建人姓名" v-decorator="['createName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建时间">
          <a-input placeholder="请输入创建时间" v-decorator="['createDate', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建时间时分秒">
          <a-input placeholder="请输入创建时间时分秒" v-decorator="['createDateTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="更新时间">
          <a-input placeholder="请输入更新时间" v-decorator="['updateDate', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="更新时间时分秒">
          <a-input placeholder="请输入更新时间时分秒" v-decorator="['updateDateTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="更新人姓名">
          <a-input placeholder="请输入更新人姓名" v-decorator="['updateName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="岗位编号">
          <a-input placeholder="请输入岗位编号" v-decorator="['positionCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="岗位名称">
          <a-input placeholder="请输入岗位名称" v-decorator="['positionName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="组织编号">
          <a-input placeholder="请输入组织编号" v-decorator="['orgCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="组织名称">
          <a-input placeholder="请输入组织名称" v-decorator="['orgName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="停用启用状态">
          <a-input placeholder="请输入停用启用状态" v-decorator="['status', validatorRules.status ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否删除">
          <a-input placeholder="请输入是否删除" v-decorator="['deleteStatus', validatorRules.deleteStatus ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注">
          <a-input placeholder="请输入备注" v-decorator="['remarks', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="saasid">
          <a-input placeholder="请输入saasid" v-decorator="['saasid', validatorRules.saasid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="网点类型">
          <a-input placeholder="请输入网点类型" v-decorator="['clientType', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="网点编码">
          <a-input placeholder="请输入网点编码" v-decorator="['clientCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="网点名称">
          <a-input placeholder="请输入网点名称" v-decorator="['clientName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访人">
          <a-input placeholder="请输入拜访人" v-decorator="['visitUserName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访人名">
          <a-input placeholder="请输入拜访人名" v-decorator="['visitUserRealname', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访人职位">
          <a-input placeholder="请输入拜访人职位" v-decorator="['visitPosCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访人职位名">
          <a-input placeholder="请输入拜访人职位名" v-decorator="['visitPosName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访日期">
          <a-input placeholder="请输入拜访日期" v-decorator="['visitDate', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="被协访线路编号">
          <a-input placeholder="请输入被协访线路编号" v-decorator="['assistId', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访类型(0临时1计划2协访)">
          <a-input placeholder="请输入拜访类型(0临时1计划2协访)" v-decorator="['visitType', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访顺序">
          <a-input-number v-decorator="[ 'visitOrder', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访状态;0:未拜访 1:拜访中 2:已拜访">
          <a-input-number v-decorator="[ 'visitStatus', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访提醒">
          <a-input placeholder="请输入拜访提醒" v-decorator="['visitRemind', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="修改拜访计划时间">
          <a-input placeholder="请输入修改拜访计划时间" v-decorator="['updateVisitTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="类型;1上级指派,2为新增3为修改4取消">
          <a-input placeholder="请输入类型;1上级指派,2为新增3为修改4取消" v-decorator="['type', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="错店描述">
          <a-input placeholder="请输入错店描述" v-decorator="['errorTip', {}]" />
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "SfaVisitLineModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        status:{rules: [{ required: true, message: '请输入停用启用状态!' }]},
        deleteStatus:{rules: [{ required: true, message: '请输入是否删除!' }]},
        saasid:{rules: [{ required: true, message: '请输入saasid!' }]},
        },
        url: {
          add: window._CONFIG['domianSfaURL']+"/visit/sfaVisitGroupController/saveOrUpdate",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createName','createDate','createDateTime','updateDate','updateDateTime','updateName','positionCode','positionName','orgCode','orgName','status','deleteStatus','remarks','saasid','clientType','clientCode','clientName','visitUserName','visitUserRealname','visitPosCode','visitPosName','visitDate','assistId','visitType','visitOrder','visitStatus','visitRemind','updateVisitTime','type','errorTip'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
              httpurl+=this.url.add;
              method = 'post';

            let formData = Object.assign(this.model, values);
            //时间格式化
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
                that.close();
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>